package com.eastfair.matching.controller;

import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.annotation.annotation.security.PreAuth;
import com.eastfair.core.utils.ConvertUtil;
import com.eastfair.matching.entity.ComplementServiceItem;
import com.eastfair.matching.dto.ComplementServiceItemSaveDTO;
import com.eastfair.matching.dto.ComplementServiceItemUpdateDTO;
import com.eastfair.matching.dto.ComplementServiceItemPageQuery;
import com.eastfair.matching.service.ComplementServiceItemService;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.eastfair.boot.controller.SuperController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.echo.core.EchoService;
import com.eastfair.core.base.R;
import com.eastfair.matching.vo.ComplementServiceItemVO;
import com.eastfair.venueservice.dto.ServiceItemDTO;
import com.eastfair.venueservice.dto.ServiceItemQuery;
import com.eastfair.venueservice.dto.ServiceSpecsSaveDTO;
import com.eastfair.venueservice.vo.ServiceItemVO;
import com.eastfair.venueservice.vo.ServiceSpecsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.eastfair.boot.request.PageParams;
import com.eastfair.core.context.ContextUtil;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 前端控制器
 * 配套服务项
 * </p>
 *
 * @author lyw
 * @date 2022-07-15
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/complementServiceItem")
@Api(value = "ComplementServiceItem", tags = "配套服务项")
@PreAuth(replace = "matching:complementServiceItem:")
public class ComplementServiceItemController extends SuperController<ComplementServiceItemService, Long, ComplementServiceItem, ComplementServiceItemPageQuery, ComplementServiceItemSaveDTO, ComplementServiceItemUpdateDTO> {

    @Autowired
    private EchoService echoService;
    @Autowired
    private ComplementServiceItemService complementServiceItemService;

    @Override
    public void handlerResult(IPage<ComplementServiceItem> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }
    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<ComplementServiceItem> complementServiceItemList = list.stream().map((map) -> {
            ComplementServiceItem complementServiceItem = ComplementServiceItem.builder().build();
            //TODO 请在这里完成转换
            return complementServiceItem;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(complementServiceItemList));
    }



    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<ComplementServiceItemPageQuery> params) {
        ComplementServiceItemPageQuery pageQuery = params.getModel();
        //分页处理
        if(ContextUtil.getProjectId()!=null){
            pageQuery.setProjectId(ContextUtil.getProjectId());
        }
    }

    /**
     * 配套服务项列表
     * @param params
     * @return
     */
    @ApiOperation(value = "配套服务项列表")
    @PostMapping(value = "/queryComplementServiceItemList")
    public R<IPage<ServiceItemVO>> queryComplementServiceItemList(@RequestBody PageParams<ServiceItemQuery> params) {
        IPage<ServiceItemVO> page = complementServiceItemService.queryComplementServiceItemList(params);
        return R.success(page);
    }


    /**
     * 修改配套服务项
     * @param serviceItemDTO
     * @return
     */
    @ApiOperation(value = "修改配套服务项")
    @SysLog("修改配套服务")
    @PostMapping(value = "/updateComplementServiceItemById")
    public R<Boolean> updateComplementServiceItemById(@RequestBody ServiceItemDTO serviceItemDTO){
        return R.success(complementServiceItemService.updateComplementServiceItemById(serviceItemDTO));
    }

    /**
     * 保存配套服务项
     * @param serviceItemDTO
     * @return
     */
    @ApiOperation(value = "保存配套服务项")
    @SysLog("添加配套服务")
    @PostMapping(value = "/saveComplementServiceItemInfo")
    public R<Boolean> saveComplementServiceItemInfo(@RequestBody ServiceItemDTO serviceItemDTO){
        return R.success(complementServiceItemService.saveComplementServiceItemInfo(serviceItemDTO));
    }



    /**
     * 上架配套服务
     * @param serviceItemDTO
     * @return
     */
    @ApiOperation(value = "上架配套服务")
    @SysLog("上架配套服务")
    @PostMapping(value = "/shelfService")
    public R<Boolean> shelfService(@RequestBody ServiceItemDTO serviceItemDTO){
        return R.success(complementServiceItemService.shelfService(serviceItemDTO));
    }


    /**
     * 下架配套服务
     * @param serviceItemDTO
     * @return
     */
    @ApiOperation(value = "下架配套服务")
    @SysLog("下架配套服务")
    @PostMapping(value = "/offShelfService")
    public R<Boolean> offShelfService(@RequestBody ServiceItemDTO serviceItemDTO){
        return R.success(complementServiceItemService.offShelfService(serviceItemDTO));
    }



    /**
     * 删除配套服务
     * @param serviceItemDTO
     * @return
     */
    @ApiOperation(value = "删除配套服务")
    @SysLog("删除配套服务")
    @PostMapping(value = "/delComplementServiceItemById")
    public R<Boolean> delComplementServiceItemById(@RequestBody ServiceItemDTO serviceItemDTO){
        return R.success(complementServiceItemService.delComplementServiceItemById(serviceItemDTO));
    }





}
